package com.cupk.wudi.practice.apidemo.utils;

import lombok.Data;


/**
 * @author mijiupro
 */

@Data
public class Result<T> {

    // 操作代码
    Integer code;

    // 提示信息
    String msg;

    // 结果数据
    T data;

    public Result(T data) {
        this.data = data;
    }

    public Result(){
        this.data=null;
    }


    public static Result success(){
        Result result=new Result();
        result.code=200;
        return result;
    }
    public static<T> Result<T> success(T data){
        Result<T> result=new Result<T>(data);
        result.code=200;
        return result;
    }

    public static<T> Result<T> success(T data,String msg){
        Result<T> result=new Result<T>(data);
        result.code=200;
        result.msg=msg;
        return result;
    }

    public static Result error(String msg){
        Result result=new Result();
        result.code=500;
        result.msg=msg;
        return result;
    }

    public static Result error(){
        Result result=new Result();
        result.code=500;
        return result;
    }



//    public Result(Integer resultCode) {
//        this.code = resultCode;
//        this.msg ="";
//    }

//    public Result(Integer resultCode, T data) {
//        this.code = resultCode;
//        this.msg = "成功查询";
//        this.data = data;
//    }
//    public Result(String msg) {
//        this.msg = msg;
//    }
//    //成功返回封装-无数据
//    public static Result<String> success() {
//        return new Result<String>(200);
//    }
//    //成功返回封装-带数据
//    public static <T> Result<T> success(T data) {
//        return new Result<T>(200, data);
//    }
//    //失败返回封装-使用默认提示信息
//    public static Result<String> error() {
//        return new Result<String>(500);
//    }
//    //失败返回封装-使用返回结果枚举提示信息
//    public static Result<String> error(Integer resultCode) {
//        return new Result<String>(resultCode);
//    }
//    //失败返回封装-使用自定义提示信息
//    public static Result<String> error(String msg) {
//        return new Result<String>(msg);
//    }
//    public static Result<String> error(Integer msg) {
//        return new Result<String>(msg);
//    }
}